﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
using System.Web.UI;
using System.Web.UI.HtmlControls;

namespace Enterprise.Adapters
{
    /// <summary>
    /// Creates a nice indented css link section instead of the messy original. It's easier to debug this code.
    /// </summary>
    public class HtmlLinkAdapter : System.Web.UI.Adapters.ControlAdapter
    {
        protected override void Render(HtmlTextWriter writer)
        {
            HtmlLink linkTag = (HtmlLink)this.Control;
            writer.Write("\t<link");
            AttributeCollection attributes = linkTag.Attributes;
            IEnumerator keys = linkTag.Attributes.Keys.GetEnumerator();
            while (keys.MoveNext())
            {
                string key = (string)keys.Current;
                writer.Write(" ");
                writer.Write(key);
                writer.Write("=\"");
                writer.Write(attributes[key].Replace("~", ""));
                writer.Write("\"");
            }
            writer.WriteLine(" />");
        }
    }
}
